package com.api.phm.util;

import com.api.common.utils.StringUtils;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;

public class CheckSystem {

    public void reloadPlcData(String ip) {
        String n = "\\\\127.0.0.1\\share";
        File newFile = new File(n + "\\test.txt");
        try {
            FileWriter fw = new FileWriter(newFile, true);
            fw.append("test");
            fw.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) {
        String order = "Wmic logicaldisk";
        Map<String, Object> map = CommandUtils.runCmdByWindows(order, "GBK", 0);
//        System.out.println(map.toString());
        List<String> list = (List<String>) map.get("data");
        List<String> title = Arrays.asList(list.get(0).split(" "));
        System.out.println("=============================== title ================================");
        System.out.println(title.toString());
        System.out.println("=============================== title ================================");
        list.remove(0);
        List<Map<String, String>> rl = new ArrayList<>();
        for (String item : list) {
            System.out.println("[item]:" + item);
            List<String> l = Arrays.asList(item.split("       "));
            if (StringUtils.isNotBlank(l.toString())) {
                Map<String, String> m = new HashMap<>();
                for (int i = 0; i < l.size(); i++) {

                    m.put(title.get(0), l.get(0));
//                if (StringUtils.isNotBlank(s)) System.out.println(s);
                }
                System.out.println("===============================================================");
                System.out.println("[MapValue]:" + m.toString());
                System.out.println("===============================================================");
                rl.add(m);
//                System.out.println(m.toString());
            }
        }
        for (Map<String, String> showMap : rl) {
            for (String key : showMap.keySet()) {
                System.out.println("===============================================================");
                System.out.println("[key]:" + key);
                System.out.println("[val]:" + showMap.get(key));
                System.out.println("===============================================================");
            }
        }
    }
}
